home *** CD-ROM | disk | FTP | other *** search
- @if-using not(ocl-file-regions)
- @use (ocl-file-regions)
- ;OCL{{{}}}
- ;OCL{{{ libs
- @if-using not(ocl-file-go-line) @lib go-line @fi
- @if-using not(ocl-file-delchar) @lib delchar @fi
- ;OCL}}}
- ;OCL{{{ vars
- ( defvar
- ( start-line ; screen position for start mark
- start-x ; start of defined block
- start-y ; "
- end-line ; screen position for end mark
- end-x ; end of defined block
- end-y ; "
- folderr ; return: could the folding be done?
- end-splitted ; return: was the last line of the block splitted?
- start-splitted ; return: was the first line of the block splitted?
- regions-help ; internal help variable
- )
- )
- ;OCL}}}
- ;OCL{{{ set-start-mark
- ( deffun set-start-mark
- ( set start-y store-line
- set start-x store-pos
- set start-line cursor-level
- )
- )
- ;OCL}}}
- ;OCL{{{ go-start-mark
- ( deffun go-start-mark
- ( set go-line-arg start-y
- go-line
- goto-counter start-x
- redraw-display
- )
- )
- ;OCL}}}
- ;OCL{{{ set-end-mark
- ( deffun set-end-mark
- ( set end-y store-line
- set end-x store-pos
- set end-line cursor-level
- )
- )
- ;OCL}}}
- ;OCL{{{ clear-marks
- ( deffun clear-marks
- ( set start-x 0
- set start-y 0
- set end-x 0
- set end-y 0
- )
- )
- ;OCL}}}
- ;OCL{{{ change-mark-counters
- ( defvar ( dummy ) )
- ( deffun change-mark-counters
- (
- ;OCL{{{ change x
- set dummy end-x
- set end-x start-x
- set start-x dummy
- ;OCL}}}
- ;OCL{{{ change y
- set dummy end-y
- set end-y start-y
- set start-y dummy
- ;OCL}}}
- ;OCL{{{ change level
- set dummy end-line
- set end-line start-line
- set start-line dummy
- ;OCL}}}
- )
- )
- ( undeclare ( dummy ) )
- ;OCL}}}
- ;OCL{{{ fold-region
- ;OCL{{{ vars
- ( defvar
- ( entered ; help, number of minimum leading spaces in given block
- bool ; help
- y ; help
- cy ; help
- )
- )
- ;OCL}}}
- ;OCL{{{ mini-x
- ( deffun mini-x
- ( goto-counter 1
- while true
- ( case
- ( test-end-line ( return-from-macro ) )
- ( test-char " ( forward-character ) )
- default
- ( if >(cy store-pos)
- ( set cy store-pos )
- fi
- return-from-macro
- )
- esac
- )
- )
- )
- ;OCL}}}
- (deffun fold-region
- ( set folderr 1
- ;OCL{{{ start-y = start, end-y = end, cy=start, y=0, entered=0
- set entered 0
- ;OCL{{{ maybe change end/start-positions
- case
- ;OCL{{{ start under end -> change
- ( pre
- ( set y -(start-y end-y) )
- >(y 0)
- ( change-mark-counters )
- )
- ;OCL}}}
- ;OCL{{{ one line, start after end
- ( and ( =(y 0)
- pre (set y -(start-x end-x) ) >(y 0)
- )
- ( change-mark-counters )
- )
- ;OCL}}}
- esac
- ;OCL}}}
- ;OCL{{{ correct marks given?
- if not(and(start-x start-y end-x end-y)) ( return-from-macro ) fi
- ;OCL}}}
- set y 0
- set cy start-y
- ;OCL}}}
- screen-off
- ;OCL{{{ go from start to end and count steps
- ;OCL{{{ go-line(start-y)
- set go-line-arg start-y
- go-line
- if test-begin-fold ( close-fold ) fi
- ;OCL}}}
- while pre ( set bool -(cy end-y) ) <>(bool 0)
- ;OCL{{{ move one step and update counters
- ( if >(bool 0)
- ;OCL{{{ under end mark
- ( set y -(y 1)
- previous-line
- if test-fold-line
- ;OCL{{{ open fold to search in this fold
- ( open-fold )
- ;OCL}}}
- else
- ;OCL{{{ cannot fold
- ( screen-on
- redraw-display
- return-from-macro
- )
- ;OCL}}}
- fi
- )
- ;OCL}}}
- else
- ;OCL{{{ handle open/close fold
- ( case
- ;OCL{{{ handle fold-open
- ( test-begin-fold ( set entered +(entered 1) ) )
- ;OCL}}}
- ;OCL{{{ handle fold-end
- ( test-end-fold
- ( if =(entered 0)
- ;OCL{{{ cannot fold
- ( screen-on
- redraw-display
- return-from-macro
- )
- ;OCL}}}
- fi
- set entered +(entered -1)
- )
- )
- ;OCL}}}
- esac
- set y +(y 1)
- next-line
- )
- ;OCL}}}
- fi
- set cy store-line
- )
- ;OCL}}}
- if or
- ( and( test-end-fold <>(1 entered))
- and(not(test-end-fold) <>(entered 0))
- test-begin-fold
- )
- ;OCL{{{ cannot fold
- ( screen-on
- redraw-display
- return-from-macro
- )
- ;OCL}}}
- fi
- ;OCL}}}
- ;OCL{{{ maybe splitt last line of the marked region
- goto-counter end-x
- forward-character
- if or(not(test-text),test-end-line,pre ( "$ ) last-message M_ERR_PO)
- ;OCL{{{ no splitt
- ( set end-splitted 0 )
- ;OCL}}}
- else
- ;OCL{{{ do the splitt
- ( set end-splitted 1
- if test-end-line ( end-of-line ) fi
- backward-character
- newline-and-indent
- newline-and-indent
- previous-line
- beginning-of-line
- do
- ( delete-character )
- while not(test-char "$)
- delete-character
- previous-line
- )
- ;OCL}}}
- fi
- ;OCL}}}
- ;OCL{{{ move back to start, set cy to minimum x-position, entered becomes invalid
- goto-counter end-x
- set cy store-pos
- mini-x
- local (y)
- ( while <>(y 0)
- ( previous-line
- set y -(y 1)
- if >(cy 1)
- ( mini-x )
- fi
- )
- )
- ;OCL}}}
- ;OCL{{{ maybe splitt first line of the marked region
- if
- and
- ( test-text,
- pre
- ( beginning-of-line
- set start-splitted -(start-x store-pos)
- goto-counter start-x
- if test-end-line ( end-of-line ) fi
- )
- >(start-splitted 0)
- )
- ;OCL{{{ do the splitt
- ( set start-splitted 1
- "$
- backward-character
- newline-and-indent
- newline-and-indent
- previous-line
- beginning-of-line
- do
- ( delete-character )
- while not(test-char "$)
- delete-character
- mini-x
- )
- ;OCL}}}
- else
- ;OCL{{{ no splitt
- ( set start-splitted 0 )
- ;OCL}}}
- fi
- ;OCL}}}
- ;OCL{{{ do the fold
- goto-counter cy
- delete-mode-view
- create-fold
- while >(y 0) ( next-line set y +(y -1))
- next-line
- create-fold
- ;OCL}}}
- screen-on
- redraw-display
- set folderr counter test-folding
- )
- )
- ;OCL{{{ undeclare
- ( undeclare ( mini-x entered bool y cy ) )
- ;OCL}}}
- ;OCL}}}
- ;OCL{{{ combine-splitted-parts-start
- ( deffun combine-splitted-parts-start
- (
- ;OCL{{{ go-line start-y
- set go-line-arg start-y
- go-line
- ;OCL}}}
- ;OCL{{{ generate $ at real start of line
- end-of-line
- newline-and-indent
- beginning-of-line
- next-line
- "$
- ;OCL}}}
- ;OCL{{{ move to start-x/y
- previous-line
- previous-line
- goto-counter start-x
- "$
- ;OCL}}}
- ;OCL{{{ remove to $
- do
- ( delete-character )
- while test-char " ;
- ;OCL}}}
- delete-character
- delete-previous-character
- )
- )
- ;OCL}}}
- ;OCL{{{ combine-splitted-parts-end
- ( deffun combine-splitted-parts-end
- (
- ;OCL{{{ go-line end-y
- set go-line-arg end-y
- go-line
- ;OCL}}}
- if and(test-text,pre ( next-line ) test-text )
- ( previous-line
- ;OCL{{{ generate $ at real start of line
- end-of-line
- newline-and-indent
- beginning-of-line
- next-line
- "$
- ;OCL}}}
- ;OCL{{{ move to end-x/y
- previous-line
- previous-line
- goto-counter end-x
- forward-character
- "$
- ;OCL}}}
- ;OCL{{{ remove to $
- do
- ( delete-character )
- while test-char " ;
- ;OCL}}}
- delete-character
- delete-previous-character
- )
- else
- ( if test-end-fold (close-fold) fi )
- fi
- )
- )
- ;OCL}}}
- ( demand-load (
- ;OCL{{{ indent-region
- @if-using (REGIONS-INDENT)
- ;OCL{{{ comment
- ; try to indent a region +x spaces
- ; x-positions are set to beginning of first and end of last line
- ; x=0: the marked lines are folded. Start- and end-line are NOT splitted and
- ; are moved complete in the fold!
- ;OCL}}}
- ( deffun ( width ) indent-region
- ( screen-off
- ;OCL{{{ fold indent stuff
- if =(start-y end-y)
- ( set go-line-arg start-y
- go-line
- if or(test-top test-view)
- ( set folderr 1 )
- else
- ( beginning-of-line
- create-fold
- next-line
- create-fold
- set folderr 0
- )
- fi
- )
- else
- ( if >(-(start-y end-y) 0) ( change-mark-counters ) fi
- set end-x 32000
- set start-x 1
- fold-region
- )
- fi
- ;OCL}}}
- if =(folderr 0)
- ;OCL{{{ shift and unfold
- ( beginning-of-line
- while >(width 0)
- ( " set width +(width -1) )
- while <>(width 0)
- ( delete-previous-character set width +(width 1) )
- unfold-fold
- )
- ;OCL}}}
- fi
- screen-on
- set-cursor-line start-line
- )
- )
- @fi
- ;OCL}}}
- ) )
- @fi
-